/**
 * @(#)ItemController.java, 2018/2/8.
 * <p/>
 * Copyright 2018 Kerr Wang, Inc. All rights reserved.
 * KERRWANG PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package org.wangzx.exercise.controller;

import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.wangzx.exercise.meta.vo.ItemVO;
import org.wangzx.exercise.meta.vo.UserVO;
import org.wangzx.exercise.service.basic.ItemService;
import org.wangzx.exercise.utils.LoginUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * @author hzwangzuxiang(ahscwzx@163.com)
 */
@Controller
@RequestMapping("/")
public class ItemController extends BaseController {
    static private final Logger logger = LoggerFactory.getLogger(ItemController.class);

    @Autowired
    private ItemService itemService;

    @RequestMapping("/show")
    public ModelAndView showItem(@RequestParam long id, HttpServletRequest request) {
        ModelAndView mav = genModelAndView("/tmpl/itemDetail");
        UserVO userVO = LoginUtils.loginCheck(request);
        ItemVO itemVO = itemService.getById(id, userVO);

        logger.info("[op:show] userVO={}, itemVO={}", JSON.toJSONString(userVO), JSON.toJSONString(itemVO));

        mav.addObject("user", userVO);
        mav.addObject("itemVO", itemVO);
        return mav;
    }
}
